/**
 * @filename:UserServiceImpl 2023-4-27
 * @project Wonder Java前后台分离框架  1.1.0
 * Copyright(c) 2022 Wonder Co. Ltd. 
 * All right reserved. 
 */
package com.wonder.app.service.impl;

import com.wonder.app.domain.User;
import com.wonder.app.vo.UserVo;
import com.wonder.app.mapper.UserDao;
import com.wonder.app.service.UserService;
import com.wonder.app.request.UserRequest;
import com.wonder.common.utils.StringUtils;
import com.wonder.common.utils.MessageUtils;
import com.wonder.common.common.AjaxResult;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**   
 * @Description:TODO(用户管理服务实现)
 *
 * @version: 1.1.0
 * @author: Wonder
 * 
 */
@Service
public class UserServiceImpl  extends ServiceImpl<UserDao, User> implements UserService  {

    /**
     * 验证用户管理信息
     * 
     * @param user
     * @param type
     * @return String
     */
    @Override
    public String validate(User user,String type){
    
    
       return "";
    }
    
    
    /*
	 * 分页返回，自定义多表分页数据返回
	 */
	@Override 
    public IPage<UserVo> selectUserVoList(UserRequest request, Page<UserVo> page){
	    QueryWrapper<UserVo> queryWrapper = new QueryWrapper<>();
	    
	    if (null != request.getId()) {
	       queryWrapper.eq("a.id", request.getId());
	      }               
             
        if (StringUtils.hasText(request.getName())) {
			    queryWrapper.like("a.name", request.getName()); 
		    } 
             
        if (StringUtils.hasText(request.getReal_name())) {
			    queryWrapper.like("a.real_name", request.getReal_name()); 
		    } 
             
        if (StringUtils.hasText(request.getPhone())) {
			    queryWrapper.like("a.phone", request.getPhone()); 
		    } 
             
	    if (null != request.getAgent()) {
	       queryWrapper.eq("a.agent", request.getAgent());
	      }               
             
	    if (null != request.getType()) {
	       queryWrapper.eq("a.type", request.getType());
	      }               
             
	    if (null != request.getStatus()) {
	       queryWrapper.eq("a.status", request.getStatus());
	      }               
             
	    if (null != request.getVip()) {
	       queryWrapper.eq("a.vip", request.getVip());
	      }               
             
	    if (null != request.getCaller()) {
	       queryWrapper.eq("a.caller", request.getCaller());
	      }               
             
        
		queryWrapper.orderByDesc("a.id");	
		IPage<UserVo> selectPage = this.baseMapper.getUserVoList(page, queryWrapper);
		return selectPage;
    }
    
    /**
	 * 返回VO单个数据
	 */
	@Override 
	public UserVo getVoById(Long id){
	    QueryWrapper<UserVo> queryWrapper=new QueryWrapper<UserVo>().eq("a.id", id);
		return this.baseMapper.getUserVoList(queryWrapper);
	}
	
    /**
	 * Description:用户管理分页返回
	 * @param request //检索条件
	 * @param page //分页参数
	 * @return IPage<User>   //分页记录
	 */
	@Override 
	public IPage<User> selectList(UserRequest request, Page<User> page){
	    LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
	    
	    if (null != request.getId()) {
	       lambdaQueryWrapper.eq(User::getId, request.getId());
	      }               
             
        if (StringUtils.hasText(request.getName())) {
			    lambdaQueryWrapper.like(User::getName, request.getName()); 
		    } 
             
        if (StringUtils.hasText(request.getReal_name())) {
			    lambdaQueryWrapper.like(User::getReal_name, request.getReal_name()); 
		    } 
             
        if (StringUtils.hasText(request.getPhone())) {
			    lambdaQueryWrapper.like(User::getPhone, request.getPhone()); 
		    } 
             
	    if (null != request.getAgent()) {
	       lambdaQueryWrapper.eq(User::getAgent, request.getAgent());
	      }               
             
	    if (null != request.getType()) {
	       lambdaQueryWrapper.eq(User::getType, request.getType());
	      }               
             
	    if (null != request.getStatus()) {
	       lambdaQueryWrapper.eq(User::getStatus, request.getStatus());
	      }               
             
	    if (null != request.getVip()) {
	       lambdaQueryWrapper.eq(User::getVip, request.getVip());
	      }               
             
	    if (null != request.getCaller()) {
	       lambdaQueryWrapper.eq(User::getCaller, request.getCaller());
	      }               
             
        
		lambdaQueryWrapper.orderByDesc(User::getId);	
		Page<User> selectPage = this.baseMapper.selectPage(page, lambdaQueryWrapper);
		return selectPage;
    }
        
	/**
	 * 禁用
	 */
	@Override  
	public AjaxResult<Object> forbidden(User user){
	   this.baseMapper.updateById(user);
	  return AjaxResult.success();
	}
	
	/**
	 * 启用 
	 */
	@Override  
	public AjaxResult<Object> unforbidden(User user){
	   this.baseMapper.updateById(user);
	  return AjaxResult.success();
	}
	
    
	
}